package com.zkingsoft.plugin.util;

import java.sql.Connection;
import java.sql.DriverManager;

import com.zkingsoft.model.Dictionary;

public class DBHelper {
	private static final String DRIVER="com.mysql.jdbc.Driver";
//	private  static String URL="jdbc:mysql://47.88.21.194:3306/game_test";
//	public  static String USERNAME = "jyymysql";
//	public static  String PASSWORD = "jyy432524mysql1992";
	
	
	static{
		try {
			Class.forName(DRIVER);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static  Connection getConnection(Dictionary dict){
		try {
			return DriverManager.getConnection("jdbc:mysql://"+dict.getIp()+":3306/"+dict.getName(), dict.getUserName(), dict.getPassword());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	
	public static  void closeConnection(Connection conn){
		try {
			if(conn!=null&&!conn.isClosed()){
				conn.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
